//图片展示  自带展位图位图
import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_svg/svg.dart';

class PlaceHolderImgWidget extends StatelessWidget {
  final String? url;
  final Map<String, bool>? indicatorState;
  final String? name;
  PlaceHolderImgWidget(this.url, {this.indicatorState, this.name});
  @override
  Widget build(BuildContext context) {
    if (url != null && url!.length > 0) {
      if ((url?.contains('http'))??false) {
        return CachedNetworkImage(
            imageUrl: url ?? '',
            placeholder: (context, url) =>
                CupertinoActivityIndicator()); //Image.network(url, fit: BoxFit.cover);
      }
      return Image(
          gaplessPlayback: true,
          fit: BoxFit.cover,
          image: MemoryImage(base64.decode(url ?? '')),
          loadingBuilder: (indicatorState != null) && (indicatorState?[name]??false)
              ? (context, widget, event) => CupertinoActivityIndicator()
              : null);
    } else {
      return SvgPicture.asset(
        'assets/svg/default_service.svg',
        package: 'chat_online_customers',
        width: 60,
        height: 60,
      );
    }
  }
}